import { request } from '@/utils/request';

import {Result} from '@/types/axios'
import { AccessTokenInfo, PasswordLoginDto, MemberInfoDto, MemberAddDto, PasswordChangeDto } from '@/api/model/memberModel'
import { PageData } from '@/api/model/pageModel'
const Api = {
  PasswordLogin: '/member/pwd/login',
  MemberList: '/member/list',
  AddMember: '/member/add',
  PasswordChange: '/member/pwd/change',
  LoginInfo:'/member/info',
  DeleteMember:'/member/delete'
};

//获取登录用户
export function getLoginInfo()
{
  return request.get<Result<MemberInfoDto>>({
    url:Api.LoginInfo
  })
}

//密码登录
export function passwordLogin(dto: PasswordLoginDto) {
  return request.post<AccessTokenInfo>({
    url: Api.PasswordLogin,
    data: dto
  });
}
//获取成员列表
export function getList(page: number, pageSize: number) {
  return request.get<PageData<MemberInfoDto>>({
    url: Api.MemberList + "?page=" + page + "&pageSize=" + pageSize
  })
}
//增加成员
export function addMember(dto: MemberAddDto) {
  return request.post<string>({
    url: Api.AddMember,
    data: dto
  })
}


//更换密码
export function changeLoginPwd( dto:PasswordChangeDto) {
  return request.post<string>({
    url: Api.PasswordChange,
    data: dto
  })
}

//删除成员
export function deleteMember(memberId:number){
  return request.delete<string>({
    url:Api.DeleteMember+'?id='+memberId,
  })
}